import download
import download2
import json
import os


class Infinit:
    def __iter__(self):
        return self

    def __next__(self):
        return None


def downloadMultiPart():
    bvId = input('输入视频BV号：')
    startPart = input('输入起始P:')
    isVideo = input("是否爬取视频：(默认false)")

    file_path = ''
    with open("./config.json", 'rb') as f:
        config = json.load(f)
        file_path = config['file_path']
    if not os.path.isdir(file_path):
        os.makedirs(file_path)

    if(startPart == ''):
        startPart = '1'
    start = int(startPart)

    if(isVideo == "true"):
        for i in Infinit():
            try:
                download.single_download2(bvId+'?p='+str(start), file_path)
                # time.sleep(random.randint(1, 3))
                start = start+1
            except:
                print('下载完成！')
                break
    else:
        for i in Infinit():
            try:
                download.single_download(bvId+'?p='+str(start), file_path)
                # time.sleep(random.randint(1, 3))
                start = start+1
            except:
                print('下载完成！')
                break

    # BV1sV411k749
